package indi.zhifa.core.common.web.config.ansc;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Configuration
public class ThreadPoolConfig {

    static final Integer FIXED_NUM = 2;
    static final Float STEALING_EXECUTOR_PERCENT = 0.3f;


    @Bean(name = "fixedExecutor")
    public ExecutorService fixedExecutorService() {
        return Executors.newFixedThreadPool(1);
    }

    @Primary
    @Bean(name = "workStealingExecutor")
    public ExecutorService workStealingExecutorService() {
        return Executors.newWorkStealingPool(Math.max(2,Runtime.getRuntime().availableProcessors() * 2));
    }

    @Bean(name = "cachedExecutor")
    public ExecutorService cachedExecutorService() {
        return Executors.newCachedThreadPool();
    }

}
